<script setup lang='ts'>
// provide 用来给后代组件传递数据,也可以传递函数，且可以携带参数
import ProvideCom from "@/components/ProvideCom.vue";
import {provide, reactive} from 'vue'

// 给后代组件传递数据
// provide('user', {name: '张三', age: 18})

const state = reactive({name: '张三', age: 18})
// const user = {name: '张三', age: 18}
provide('user', state)

function changeName(val: string) {
    state.name = val
}

provide('change', changeName)


</script>
<template>
    <div>
        <button @click='changeName'>修改 name</button>

        <ProvideCom />
    </div>
</template>
<style>
    
</style>